package com.lu.project.controller;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lu.project.common.BaseResponse;
import com.lu.project.common.ResultUtils;
import com.lu.project.exception.ErrorCode;
import com.lu.project.exception.ThrowUtils;
import com.lu.project.model.dto.MemberElderDto.MemberElderDto;
import com.lu.project.model.dto.message.MessageTaskAddRequest;
import com.lu.project.model.dto.message.MessageTaskListRequest;
import com.lu.project.model.entity.MessageTask;
import com.lu.project.model.vo.message.MessageTaskListVo;
import com.lu.project.service.MessageTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 客户老人关联 Controller
 */
@RestController
@RequestMapping("/message")
@Api(tags = "消息待办")
public class MessageTaskController {

    @Resource
    private MessageTaskService messageTaskService;

    /**
     * 新增消息待办关联记录
     *
     * @param messageTaskAddRequest
     * @return 操作结果
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增待办")
    public BaseResponse add(@RequestBody @Validated MessageTaskAddRequest messageTaskAddRequest) {
        ThrowUtils.throwIf(messageTaskAddRequest==null, ErrorCode.PARAMS_ERROR);
        messageTaskService.add(messageTaskAddRequest);
        return ResultUtils.success("新增待办成功");
    }

    /**
     * 删除消息待办关联记录
     *
     * @param id
     * @return 操作结果
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除待办")
    public BaseResponse add(Long id) {
        ThrowUtils.throwIf(id==null, ErrorCode.PARAMS_ERROR);
        messageTaskService.getBaseMapper().deleteById(id);
        return ResultUtils.success("删除当前待办成功");
    }

    /**
     * 新增消息待办关联记录
     *
     * @param messageTaskAddRequest
     * @return 操作结果
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改待办")
    public BaseResponse update(@RequestBody @Validated MessageTaskAddRequest messageTaskAddRequest) {
        ThrowUtils.throwIf(messageTaskAddRequest==null, ErrorCode.PARAMS_ERROR);
        ThrowUtils.throwIf(messageTaskAddRequest.getId()==null,ErrorCode.PARAMS_ERROR,"id不能为空");
        messageTaskService.updateMeg(messageTaskAddRequest);
        return ResultUtils.success("待办修改成功");
    }

    /**
     * 新增消息待办关联记录
     *
     * @param messageTaskListRequest
     * @return 操作结果
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询待办")
    public BaseResponse<Page<MessageTaskListVo>> list(@RequestBody @Validated MessageTaskListRequest messageTaskListRequest) {
        ThrowUtils.throwIf(messageTaskListRequest==null, ErrorCode.PARAMS_ERROR);
        Page<MessageTaskListVo> page = messageTaskService.queryMsg(messageTaskListRequest);

        return ResultUtils.success(page);
    }

}
